package cn.yuanqiao.quartz.task;

import cn.yuanqiao.common.utils.DateUtils;
import cn.yuanqiao.common.utils.StringUtils;
import cn.yuanqiao.hengtaiOrganization.service.ISOrganizationService;
import cn.yuanqiao.quartz.domain.SysJobLog;
import cn.yuanqiao.quartz.mapper.SysJobLogMapper;
import cn.yuanqiao.quartz.service.ISysJobLogService;
import cn.yuanqiao.quartz.util.MethodDescription;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @ProjectName: cn.yuanqiao.quartz.task
 * @ClassName: OrganizationHengtaiTask
 * @Author: lenovo
 * @Description: hbWang
 * @Date: 2025/3/31 16:03
 * @Version: 1.0
 **/
@Component("htOrganization")
public class OrganizationHengtaiTask {
    @Autowired
    ISOrganizationService organizationService;
    @Autowired
    SysJobLogMapper sysJobLogMapper;
    private static final Logger log = LoggerFactory.getLogger(OrganizationHengtaiTask.class);
    @MethodDescription("人员同步，需要传入tenantCode")
    public void task(String tenantCode)
    {
        if(StringUtils.isNotEmpty(tenantCode)){
            Date start = new Date();
            log.info("恒泰人员同步任务开始="+ DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,start));
            SysJobLog sysJobLog = new SysJobLog();
            sysJobLog.setTenantCode(tenantCode);
            sysJobLog.setStatus("0");
            sysJobLog.setInvokeTarget("htOrganization.task('"+tenantCode+"')");
            SysJobLog sysJobLog1 = sysJobLogMapper.selectJobLogListTopOne(sysJobLog);
            organizationService.organizationList(tenantCode,null);
            Date end = new Date();
            log.info("恒泰人员同步任务结束="+ DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,end));
            log.info("耗时="+(end.getTime()-start.getTime())+"毫秒");
        }else {
            log.error("TenantCode is null");
        }


    }
}
